package com.legend.security;

import java.util.Dictionary;
import java.util.Hashtable;

import com.legend.utils.ReturnResult;
import com.legend.utils.Status;
import com.legend.utils.i18nUtils;

/**
 * User: ChuanQi Date: 13-6-3 Time: 下午11:19 To change this template use File |
 * Settings | File Templates.
 */
public class PermissionBase {
	/*
	 * 检查用户权限
	 * 
	 * @param permissionType权限类型
	 * 
	 * @param moduleCode模块代码
	 * 
	 * @return OperateStatus
	 */
	public ReturnResult CheckPermission(PermissionType permissionType, String moduleCode) {
		Integer permissionValue = permissionType.getValue();
		Integer userPermissionValue = this.UserPermission(moduleCode);
		ReturnResult result = new ReturnResult();
		if ((userPermissionValue & permissionValue) == permissionValue) {
			result.setStatus(Status.SUCCESS);
			result.setMsg(i18nUtils.getVal("100001000"));
        } else {
			result.setStatus(Status.NOPOWER);
			result.setMsg(i18nUtils.getVal("200001006"));
        }
		return result;
	}

	/*
	 * 用户模块权限列表,key是模块代码 value是权限总值
	 */
	public Dictionary<String, Integer> UserPermissions() {
		Dictionary<String, Integer> dic = new Hashtable<String, Integer>();
		return dic;
	}

	/*
	 * 当前模块用户权限值
	 */
	public Integer UserPermission(String moduleCode) {
		Dictionary<String, Integer> dic = this.UserPermissions();
		return dic.get(moduleCode);
	}

}
